package com.itbaizhan.swaggerdemo.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;

import static com.google.common.base.Predicates.not;
import static com.google.common.base.Predicates.or;
import static springfox.documentation.builders.RequestHandlerSelectors.withMethodAnnotation;


/*swagger配置类*/
@Configuration
public class SwaggerConfig {

    /*返回docker对象*/
    @Bean
    public Docket getDlcker(){
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(swaggerDemoApiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.itbaizhan.swaggerdemo.controller"))
                //自定义注解设置不需要生成接口文档的方法  告诉文档有这注解决注不用生成文档
                .apis(not(withMethodAnnotation(NotIncludeSwagger.class)))
                //设置访问文档的路径
                .paths(or(PathSelectors.regex("/people/.*"),PathSelectors.regex("/person/.")))
                .build();
    }
/*返回信息类对象*/
    private ApiInfo swaggerDemoApiInfo(){
        return new ApiInfoBuilder()
                .contact(new Contact("北京尚学堂","http://www.bjsxt.com","xxxx@163.com"))
                //文档标题
                .title("swagger的标题")
                //文档描述
                .description("swagger的描述")
                //文档版本
                .version("1.0.0")
                .build();
    }
}
